/*
 * $Id: endian.h,v 1.7 2005-12-11 10:35:08 bacon Exp $
 */

#ifndef _XP_BAS_ENDIAN_H_
#define _XP_BAS_ENDIAN_H_

#include <xp/types.h>
#include <xp/macros.h>

/* 
 * MACRO: XP_ENDIAN_BIG
 *   XP_ENDIAN_BIG is defined is if the system store the most significant byte 
 *   of multi-byte data at the lowest memory address.
 */

/* 
 * MACRO: XP_LITTLE_BIG
 *   XP_LITTLE_BIG is defined is if the system store the least significant byte 
 *   of multi-byte data at the lowest memory address.
 */

#ifdef __cplusplus
extern "C" {
#endif

/* 
 * FUNCTION: xp_is_endian_big
 *   Tests if the system is big-endian
 *
 * RETURNS:
 *   *xp_true* if the system is big-endian, *xp_false* otherwise.
 * 
 * SEE ALSO:
 *   <xp_is_endian_little>
 */
xp_bool_t xp_is_endian_big (void);

/* 
 * FUNCTION: xp_is_endian_little
 *   Tests if the system is little-endian
 *
 * RETURNS:
 *   *xp_true* if the system is little-endian, *xp_false* otherwise.
 *
 * SEE ALSO:
 *   <xp_is_endian_big>
 */
xp_bool_t xp_is_endian_little (void);

/* 
 * FUNCTION: xp_ntoh16
 *   Converts a 16-bit integer from network byte order to host byte order
 *
 * PARAMETERS:
 *   x - [in] a 16-bit integer in network byte order
 *
 * RETURNS:
 *   16-bit integer in host byte order
 *
 * SEE ALSO:
 *   <xp_hton16>
 */
xp_uint16_t xp_ntoh16 (xp_uint16_t x);

/* 
 * FUNCTION: xp_hton16
 *   Converts a 16-bit integer from host byte order to network byte order
 * 
 * PARAMETERS:
 *   x - [in] a 16-bit integer in host byte order
 *
 * RETURNS:
 *   16-bit integer in network byte order
 *
 * SEE ALSO:
 *   <xp_ntoh16>
 */
xp_uint16_t xp_hton16 (xp_uint16_t x);

/* 
 * FUNCTION: xp_ntoh32
 *   Converts a 32-bit integer from network byte order to host byte order
 *
 * PARAMETERS:
 *   x - [in] a 32-bit integer in network byte order
 *
 * RETURNS:
 *   A 32-bit integer in host byte order
 *
 * SEE ALSO:
 *   <xp_hton32>
 */
xp_uint32_t xp_ntoh32 (xp_uint32_t x);

/* 
 * FUNCTION: xp_hton32
 *   Converts a 32-bit integer from host byte order to network byte order
 *
 * PARAMETERS:
 *   x - [in] a 32-bit integer in host byte order
 *
 * RETURNS:
 *   A 32-bit integer in network byte order
 *
 * SEE ALSO:
 *   <xp_ntoh32>
 */
xp_uint32_t xp_hton32 (xp_uint32_t x);

#ifdef __cplusplus
}
#endif

#endif

